//
//  FPIncreaseLimitDetailController.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/4/9.
//

#import "FPIncreaseLimitDetailController.h"
#import "FPIncreaseLimitDetailHeader.h"
#import "FPIncreaseLimitDetailCell.h"
#import "FPIncreaseLimitDetailModel.h"

@interface FPIncreaseLimitDetailController () <UITableViewDelegate , UITableViewDataSource>

@property (nonatomic , strong) FPIncreaseLimitDetailHeader *headerView;

@end

@implementation FPIncreaseLimitDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)initUI {
    
    [self setTitle:@"提额专区" style:(XYCustomNavigationStyleWhite) hiddenBackBtn:NO];
    
    self.view.backgroundColor = MAIN_VIEW_BACKGROUND_COLOR;
    
    UIImageView *iv = [[UIImageView alloc] init];
    iv.image = IMG(@"bg_increase_limit_detail_head");
    [self.view addSubview:iv];
    iv.frame = CGRectMake(0.f, UIDevice.navigationFullHeight, SCREEN_WIDTH, 304.f / 375.f * SCREEN_WIDTH);
    
    self.headerView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(FPIncreaseLimitDetailHeader.class) owner:nil options:nil].lastObject;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = UIColor.clearColor;
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headerView;
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, SCREEN_WIDTH, 50.f)];
    self.tableView.tableFooterView = v;
    
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(16.f, 0.f, SCREEN_WIDTH, 50.f)];
    lab.text = @"温馨提示：保持良好的还款习惯，也有机会提额哦";
    lab.textColor = [UIColor hexColor:@"#9A9A9A"];
    [v addSubview:lab];
    lab.font = FONT(12.f);
    
    [self getData];
}

- (void)getData {
    
    NSArray *authenticationArray = @[@"芝麻分截图认证" , @"借呗截图认证" , @"花呗截图认证" , @"社保截图认证" , @"车辆认证" , @"公积金截图认证" , @"房产认证"];
    NSArray *authenticationImageArray = @[@"icon_update_amount_zhima" , @"icon_update_amount_jiebei" , @"icon_update_amount_huabei" , @"icon_update_amount_shebao" , @"icon_update_amount_cheliang" , @"icon_update_amount_gongjijin" , @"icon_update_amount_fangchan"];
    
    [self.dataSource removeAllObjects];
    
    for (NSUInteger i = 0; i < authenticationArray.count; i ++) {
        
        FPIncreaseLimitDetailModel *m = [[FPIncreaseLimitDetailModel alloc] init];
        m.title = authenticationArray[i];
        m.avatar = authenticationImageArray[i];
        m.subTitle = @"10000";
        
        [self.dataSource addObject:m];
    }
    
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 65.f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    FPIncreaseLimitDetailCell *cell;
    
    if (!cell) {
        
        cell = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(FPIncreaseLimitDetailCell.class) owner:nil options:nil].lastObject;
    }
    
    FPIncreaseLimitDetailModel *model = self.dataSource[indexPath.row];
    
    [cell setAmountToSubTltleLab:model.subTitle];
    cell.titleLab.text = model.title;
    cell.avatarImgView.image = IMG(model.avatar);
    
    cell.confirmBtn.indexPath = indexPath;
    
    if (indexPath.row == 3) {
        
        [cell.confirmBtn setTitle:@"去提额" forState:(UIControlStateNormal)];
    }
    else {
        
        [cell.confirmBtn setTitle:@"去认证" forState:(UIControlStateNormal)];
    }
    
    if (indexPath.row == 0) {
      
        [UIView setCornerForView:cell.backView withRadius:8.f bounds:CGRectMake(0.f, 0.f, SCREEN_WIDTH - 32.f, 65.f) corners:(UIRectCornerTopLeft | UIRectCornerTopRight)];
    }
    else if (indexPath.row == self.dataSource.count - 1) {
     
        cell.lineView.hidden = YES;
        [UIView setCornerForView:cell.backView withRadius:8.f bounds:CGRectMake(0.f, 0.f, SCREEN_WIDTH - 32.f, 65.f) corners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)];
    }
    
    return cell;
}




@end
